package com.xxxx.order.controller;

import com.xxxx.api.pojo.Admin;
import com.xxxx.api.service.CartService;
import com.xxxx.api.utils.LoginUserUtil;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author Lionel
 * @Date 2020/11/6 22:18
 * Created by IntelliJ IDEA 2020.1.
 * Project: EgoShop
 * Description：购物车控制层
 */
@Controller
@RequestMapping("/cart")
public class CartController {

    @Reference(version = "1.0")
    private CartService cartService;

    /**
     * 获取购物车内商品数量
     * @return
     */
    @RequestMapping("/getCartNum")
    @ResponseBody
    public Integer getCartNum(HttpServletRequest request){
        int userId = LoginUserUtil.releaseUserIdFromCookie(request);
        Admin admin = new Admin();
        admin.setAdminId((short) userId);
        return cartService.getCartNum(admin);
    }


}
